import {ILoginParams} from "interface/login"
import {LOGIN_URI, LOGOUT_URL, ResponseType, SUCCESS_CODE} from "constant/app";
import {loginService} from "../api/request/loginService";
import {IErrorFn, IResult, ISuccessFn, ISuccessInnerFn} from "../interface/app";


const successFn:ISuccessInnerFn=(success,error)=>{
    return (res)=>{
        const result:IResult=res.data;
        if(result.code!==SUCCESS_CODE){
            error(result)
            return
        }
        success(result)
    }
};

export async function loginRequest(params:ILoginParams,success:ISuccessFn,error:IErrorFn){
    return loginService.post(LOGIN_URI,params,{responseType:ResponseType.JSON}).then(successFn(success,error)).catch(error)
}

export async function logoutRequest(success:ISuccessFn,error:IErrorFn){
    return loginService.get(LOGOUT_URL,{responseType:ResponseType.JSON}).then(successFn(success,error)).catch(error)
}


export async function getVerifyImg(url:string,success:ISuccessFn,error:IErrorFn){
    return loginService.get(url,{responseType:ResponseType.JSON}).then(successFn(success,error)).catch(error)
}
